package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.WebUserRecommendAward;
import com.ruoyi.system.service.IWebUserRecommendAwardService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户推荐奖励Controller
 * 
 * @author wsliupan@126.com
 * @date 2021-05-30
 */
@Controller
@RequestMapping("/system/recommendAward")
public class WebUserRecommendAwardController extends BaseController
{
    private String prefix = "system/recommendAward";

    @Autowired
    private IWebUserRecommendAwardService webUserRecommendAwardService;

    @RequiresPermissions("system:recommendAward:view")
    @GetMapping()
    public String recommendAward()
    {
        return prefix + "/recommendAward";
    }

    /**
     * 查询用户推荐奖励列表
     */
    @RequiresPermissions("system:recommendAward:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WebUserRecommendAward webUserRecommendAward)
    {
        startPage();
        List<WebUserRecommendAward> list = webUserRecommendAwardService.selectWebUserRecommendAwardList(webUserRecommendAward);
        return getDataTable(list);
    }

    /**
     * 导出用户推荐奖励列表
     */
    @RequiresPermissions("system:recommendAward:export")
    @Log(title = "用户推荐奖励", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WebUserRecommendAward webUserRecommendAward)
    {
        List<WebUserRecommendAward> list = webUserRecommendAwardService.selectWebUserRecommendAwardList(webUserRecommendAward);
        ExcelUtil<WebUserRecommendAward> util = new ExcelUtil<WebUserRecommendAward>(WebUserRecommendAward.class);
        return util.exportExcel(list, "用户推荐奖励数据");
    }

    /**
     * 新增用户推荐奖励
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存用户推荐奖励
     */
    @RequiresPermissions("system:recommendAward:add")
    @Log(title = "用户推荐奖励", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WebUserRecommendAward webUserRecommendAward)
    {
        return toAjax(webUserRecommendAwardService.insertWebUserRecommendAward(webUserRecommendAward));
    }

    /**
     * 修改用户推荐奖励
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        WebUserRecommendAward webUserRecommendAward = null;
        if(id == null || id ==  -1){
            webUserRecommendAward = new WebUserRecommendAward();
        }else{
            webUserRecommendAward = webUserRecommendAwardService.selectWebUserRecommendAwardById(id);
        }
        mmap.put("webUserRecommendAward", webUserRecommendAward);
        return prefix + "/edit";
    }

    /**
     * 修改保存用户推荐奖励
     */
    @RequiresPermissions("system:recommendAward:edit")
    @Log(title = "用户推荐奖励", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WebUserRecommendAward webUserRecommendAward)
    {
        return toAjax(webUserRecommendAwardService.updateWebUserRecommendAward(webUserRecommendAward));
    }

    /**
     * 删除用户推荐奖励
     */
    @RequiresPermissions("system:recommendAward:remove")
    @Log(title = "用户推荐奖励", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(webUserRecommendAwardService.deleteWebUserRecommendAwardByIds(ids));
    }
}
